package com.higgins.eventtracking.server;

import java.util.List;
import java.util.Random;

import javax.jdo.Query;
import com.higgins.eventtracking.client.dto.QuestionDTO;
import com.higgins.eventtracking.server.dataModel.Question;

public class ELearningTrackingDataService extends DataStoreService	{
	public void insertQuestion(QuestionDTO dto)	{
		Question question = new Question(dto);
		pm.makePersistent(question);
	}
	@SuppressWarnings("unchecked")
	public Question retrieveQuestion(String category)	{
		Random myRandom = new Random();
		Query query;
		query=pm.newQuery(Question.class);
		query.setFilter("category==categoryParam");
		query.declareParameters("String categoryParam");
		List<Question> result = (List<Question>) query.execute(category);
		int size = result.size();
		Integer randomIndex = myRandom.nextInt(size);
		Question questionForReturning = result.size()>0?result.get(randomIndex):null;
		return questionForReturning;
	}
}
